Language

Visual Basic

C#

Show All

fcSDK Documentation Send comments on this topic.

Developer Walkthrough - Transaction support

Transaction support


The fcSDK supports transactional database operations within FCFL.NET and the FCFL and API Toolkit COM Compatibility Layer. This support is easy to use and maps well to the classic transactional operations of Begin, Commit, and Rollback.

API Toolkit / Generic Transaction Operations

Here is an example of a typical usage scenario where the developer uses some API Toolkit operations mixed with some ClarifyGeneric updates:

[C#] 

using System.Data;

using FChoice.Common.Data;
using FChoice.Foundation;
using FChoice.Foundation.Clarify;
using FChoice.Toolkits.Clarify;
using FChoice.Toolkits.Clarify.Interfaces;
using FChoice.Toolkits.Clarify.Support;

...

InterfacesToolkit interfaceToolkit = new InterfacesToolkit(session);
SupportToolkit supportToolkit = new SupportToolkit(session);

using( IDbConnection connection = DbProviderFactory.Provider.GetConnection() )
{
   connection.Open();

   using(IDbTransaction transaction = connection.BeginTransaction())
   {
      try
      {
         string addr1 = "123 Street";
         string city = "Austin";
         string state = "TX";
         string zip = "78759";
         string country = "USA";
         string timeZone = "CST";

         //unique test identifier (first, last, phone) for a contact
         string firstName = Guid.NewGuid().ToString().Substring(0,10);
         string lastName = Guid.NewGuid().ToString().Substring(0,10);
         string phone = Guid.NewGuid().ToString().Substring(0,10);

         CreateAddressSetup addressSetup = new CreateAddressSetup( addr1, city, state, zip, country, timeZone);
         ToolkitResult addressResult = interfaceToolkit.CreateAddress( addressSetup, transaction );

         CreateSiteSetup siteSetup = new CreateSiteSetup(SiteType.Customer, SiteStatus.Active, addressResult.Objid);
         ToolkitResult siteResult = interfaceToolkit.CreateSite( siteSetup, transaction );

         CreateContactSetup contactSetup = new CreateContactSetup( firstName, lastName, phone, siteResult.IDNum);
         ToolkitResult contactResult = interfaceToolkit.CreateContact( contactSetup, transaction );

         ClarifyDataSet dataset = new ClarifyDataSet(session);
         ClarifyGeneric generic = dataset.CreateGeneric("phone");
         ClarifyDataRow row = generic.AddNew();
         row["phone"] = "512-555-1212";
         row["name"] = "Soft Cell";
         row.RelateByID(siteResult.Objid, "phone2site");
         row.Update(transaction);

         transaction.Commit();
      }
      catch
      {
         transaction.Rollback();
         throw;
      }
   }
}

Transactions using Compatibilty

This JavaScript example shows how to use the transaction support that is now exposed to the COM clients via the Compatibility layer. The FCSession object holds the context of the transaction.

[JavaScript] 

try
{
   FCSession.StartTransaction(null);

   var ret_int = fcinter.create_contact_list( first_name, last_name, phone, primary_site_id,
      role_name, fax_number, e_mail, mail_stop, title,
      hours, salutation,
      fld_list,type_list,val_list);

   var genMonitor = FCSession.CreateGeneric("monitor");
   genMonitor.BulkName = "transaction sample";
   genMonitor.AddNew();
   genMonitor("title") = "Monitor Name";

   var genModem = FCSession.CreateGeneric("modem");
   genModem.BulkName = "transaction sample";
   genModem.AddNew();
   genModem("device_name") = "Modem Device Name";

   genMonitor.Bulk.UpdateAll();
   FCSession.CommitTransaction();
}
catch(e)
{
   FCSession.RollbackTransaction();
   ErrorHandler("An error occured and the transaction was rolled back. Error: " + e.description)
}